<!-- 检测任务 -->
<template>
	<view class="page">
		<cu-custom bgColor="bg-white" :isBack="true">
			<block style="color: #777777;font-size: 32rpx;" slot="content">检测任务</block>
		</cu-custom>

		<view v-if="!dataEmpty" :style="{ 'height': scrollHeight + 'px' }" style="overflow: hidden;">
			<movable-refresh ref="movableRefresh" :scrollHeight="scrollHeight" :noMore="noMore" :showGoTop="true"
				@refresh="refresh" @loadMore="loadMore" @scrollTop="scrollTop">
				<view>
					<view class="content" v-for="(item, index) in list" :key="index">
						<view class="pd">
							<text class="title">{{ item.taskName }}</text>
							<p class="list-box">
								<text class="list-info">被检单位：</text>
								<text class="list-title">{{ item.enterpriseName || '暂无' }}</text>
							</p>
							<p class="list-box">
								<text class="list-info">上报时间：</text>
								<text class="list-title">{{ item.addTime || '暂无' }}</text>
							</p>
							<p class="list-box">
								<text class="list-info">任务状态：
								</text>
								<text class="list-title">{{ item.examineStatusStr || '暂无' }}</text>
							</p>
							<button class="my-btn cu-btn bg-blue shadow" @click="see_detail(item.ucId)">详情</button>
						</view>
					</view>
				</view>
			</movable-refresh>
		</view>

		<view v-if="dataEmpty" class="empty">
			<p>暂无数据</p>
		</view>
		<message />
	</view>
</template>

<script>
import movableRefresh from '@/components/zyq-movableRefresh/zyq-movableRefresh.vue'
export default {
	components: {
		movableRefresh
	},
	onLoad() {
		let system = uni.getSystemInfoSync()
		this.scrollHeight = system.windowHeight - system.statusBarHeight - 50

	},
	onShow() {
		this.refresh()
	},
	data() {
		return {
			list: [],
			scrollHeight: 300,
			noMore: false,
			pageNum: 1,
			pageSize: 10,
			dataEmpty: false
		}
	},
	methods: {
		scrollTop(scrollTop) {
			this.scrollTop = scrollTop
		},
		refresh() {
			this.pageNum = 1
			let that = this
			that.noMore = false
			let list = []
			// 封装参数
			let params = {
				"pageNum": that.pageNum,
				"pageSize": that.pageSize
			}
			// 请求数据
			let app = getApp()
			app.globalData.request({
				url: 'wx/examine/getInExamineTaskPage',
				data: {
					...params
				}
			}).then(function (res) {

				let datas = res.data.data.list
				let recors = []
				for (let i = 0; i < datas.length; i++) {
					recors.push(datas[i])
				}
				that.list = recors

				that.pageNum++
				console.info("pagenum:" + that.pageNum)

				if (res.data.data.pages === 1) {
					that.noMore = true
				}

				if (that.$refs.movableRefresh) {
					let that_ = that
					setTimeout(function () {
						that_.$refs.movableRefresh.endLoad() //刷新结束
						if (that_.list.length == 0) {
							that_.dataEmpty = true
						} else {
							that_.dataEmpty = false
						}
					}, 1000)
				}
			}).catch(function (e) {
				uni.showToast({
					title: "请稍后再试",
					icon: 'none'
				})
			})


		},
		loadMore() {
			if (this.noMore) {
				return
			}

			let list = this.list
			let that = this
			if (that.pageNum) {

			}
			// 封装参数
			let params = {
				"pageNum": this.pageNum,
				"pageSize": this.pageSize
			}
			// 请求数据
			let app = getApp()
			app.globalData.request({
				url: 'wx/examine/getInExamineTaskPage',
				data: {
					...params
				}
			}).then(function (res) {
				let datas = res.data.data.list
				for (let i = 0; i < datas.length; i++) {
					list.push(datas[i])
				}
				that.list = list


				that.pageNum++
				if (res.data.data.pages === that.pageNum) {
					that.noMore = true
				}

				if (that.$refs.movableRefresh) {
					let that_ = that
					setTimeout(function () {
						that_.$refs.movableRefresh.endLoad() //刷新结束
					}, 1000)
				}
			}).catch(function (e) {

			})
		},
		see_detail(ucId) {
			uni.navigateTo({
				url: '../jcxq/jcxq?ucId=' + ucId
			})
		}
	}
}
</script>

<style scoped>
.pd {
	background-color: #FFFFFF;
	margin: 20rpx 0;
	padding: 20rpx 0;

}

.pd text {
	display: flex;
	/* margin-left: 20rpx; */
	font-size: 24rpx;
	letter-spacing: 0.39px;
	line-height: 50rpx;
	/* color: #777; */
}

.pd .title {
	font-size: 32rpx;
	color: #333;
}

.pd .time {
	position: relative;
}

.pd .my-btn {
	position: absolute;
	right: 16px;
	margin-top: -40px;
}
</style>
